| Conditions | 3 |
| Total Lines | 21 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
| 16 | |||
| 17 | public async execute(command: UpdateShippingCostCommand): Promise<string> { |
||
| 18 | const { id, weight, price } = command; |
||
| 19 | |||
| 20 | const shippingCost = await this.shippingcostRepository.findOneById(id); |
||
| 21 | if (!shippingCost) { |
||
| 22 | throw new ShippingCostNotFoundException(); |
||
| 23 | } |
||
| 24 | |||
| 25 | if ( |
||
| 26 | weight !== shippingCost.getWeight() && |
||
| 27 | true === (await this.isShippingCostAlreadyExist.isSatisfiedBy(weight)) |
||
| 28 | ) { |
||
| 29 | throw new ShippingCostAlreadyExistException(); |
||
| 30 | } |
||
| 31 | |||
| 32 | shippingCost.update(weight, Math.round(price * 100)); |
||
| 33 | |||
| 34 | await this.shippingcostRepository.save(shippingCost); |
||
| 35 | |||
| 36 | return shippingCost.getId(); |
||
| 37 | } |
||
| 39 |